/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import java.io.File;
import javax.swing.filechooser.FileFilter;

/**
 * To define new extensions.
 *
 * @author hicham
 */
public class FilterExtension extends FileFilter {

    private String extension;
    private String description;

    public FilterExtension() {
        super();
    }

    public FilterExtension(String extension, String description) {
        this();
        if (extension.indexOf('.') == -1) {
            extension = "." + extension;
        }
        this.extension = extension;
        this.description = description;
    }

    @Override
    public boolean accept(File pathname) {
        // if the path ends with extenstion then we return true else we return false. 
        if (pathname.getName().endsWith(extension)) {
            return true;
        } else if (pathname.isDirectory()) {
            return true;
        }
        return false;
    }

    public String getExtension() {
        return extension;
    }

    public void setExtension(String extension) {
        this.extension = extension;
    }

    @Override
    public String getDescription() {
        return this.description + "(*" + extension + ")";
    }

    public void setDescription(String description) {
        this.description = description;
    }
}
